import os
import sys
import operator
import collections

if len(sys.argv)<3:
	print "usage: python convertOutput.py nodes_file trans_file"
	sys.exit()

nodesfile = sys.argv[1]
transfile = sys.argv[2]
f = open(nodesfile)
nodes = f.readlines()
nodes = dict([tuple(n.strip().split(' ', 1)) for n in nodes])
f.close()
f = open(transfile)
trans = f.readlines()
trans = [tuple(t.strip().split(' ')) for t in trans]
f.close()

"""transfile: node1, node2, p(node1|node2)"""
trans.sort(key=operator.itemgetter(1))
current = -1 
res = collections.deque()
for t in trans:
	if current != t[1]:
		if len(res)==0:
			current = t[1]
		else:
			res = sorted(list(res), key=operator.itemgetter(2), reverse=True)
			print ''.join(['"%s" "%s" %s\n'%(r[0], r[1], r[2]) for r in res])	
			current = t[1]
			res = collections.deque()
	res.append((nodes[t[0]], nodes[t[1]], float(t[2])))

res = sorted(list(res), key=operator.itemgetter(2), reverse=True)
print ''.join(['"%s" "%s" %s\n'%(r[0], r[1], r[2]) for r in res])	










	
